import net.rim.blackberry.api.browser.Browser;
import net.rim.blackberry.api.browser.BrowserSession;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;
 
public class Link extends UiApplication {
	public static void main(String[] args){
		Link instance = new Link();
		instance.enterEventDispatcher();
	}
	 
	public Link() {
		UiApplication.getUiApplication().pushScreen(new EnterURL());
	}
}

class EnterURL extends MainScreen implements FieldChangeListener{
	
	BasicEditField bef = new BasicEditField("Enter the URL : ", "");
	ButtonField mySubmitButton = new ButtonField("Submit");
	
	public EnterURL() {
			add(new RichTextField("Created by Yong Woo Lee, Yungoo Kim"));
			add(new SeparatorField());
			add(bef);
			add(mySubmitButton);
			mySubmitButton.setChangeListener(this);
	}

	public void fieldChanged(Field field, int context) {
		if (field == mySubmitButton){
			BrowserSession site = Browser.getDefaultSession();
			String a = bef.getText();
			if (!a.startsWith("http://")){
				a = "http://" + a;
			}
			site.displayPage(a);
			System.exit(0);
			
		}
		
	}
}